package com.pz.gulimall.member.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pz.gulimall.common.exception.BizCodeEnum;
import com.pz.gulimall.common.exception.RRException;
import com.pz.gulimall.member.dao.MemberFocusEntityDao;
import com.pz.gulimall.member.entity.MemberFocusEntity;
import com.pz.gulimall.member.service.MemberFocusService;
import com.pz.gulimall.member.vo.ResponseFocusReqVo;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service("memberFocusService")
public class MemberFocusServiceImpl extends ServiceImpl<MemberFocusEntityDao, MemberFocusEntity> implements MemberFocusService {

    /**
     * 发起关注
     * @param fromId 发起者ID
     * @param toId 关注对象ID
     */
    @Override
    public void addFocus(Long fromId, Long toId) {
        MemberFocusEntity memberFocus = new MemberFocusEntity(fromId, toId, 0, new Date());
        List<MemberFocusEntity> flag= list(new QueryWrapper<MemberFocusEntity>()
                .eq("from_member_id", fromId)
                .and(q -> q.eq("to_member_id", toId)));
        if(flag != null) {
            // 该关注关系已存在
            throw new RRException(BizCodeEnum.MEMBER_FOCUS_RELATION_EXISTED+"fromId-"+fromId+"; toId-"+toId);
        }
        baseMapper.insert(memberFocus);
    }

    /**
     * 响应关注
     */
    @Override
    public void responseFocus(ResponseFocusReqVo vo) {
//        update(new UpdateWrapper<MemberFocusEntity>()
//                .set("ack", vo.getAck())
//                .eq(""));
    }

    /**
     * 获取其他人关注我的数据列表
     */
    @Override
    public List<MemberFocusEntity> queryOtherFocusMe(Long userId) {
        return list(new QueryWrapper<MemberFocusEntity>().eq("to_member_id", userId));
    }
}
